﻿using System;
using System.Net;
using System.Security;
using System.Threading;

namespace Cerulean
{
  public class WebClient : System.Net.WebClient
  {
    bool _allowAutoRedirect = true;
    public bool AllowAutoRedirect
    {
      get { return _allowAutoRedirect; }
      set { _allowAutoRedirect = value; }
    }
    private System.Net.CookieContainer _cookieContainer = new System.Net.CookieContainer();
    public System.Net.CookieContainer CookieContainer
    {
      get { return _cookieContainer; }
      private set { _cookieContainer = value; }
    }

    [SecurityCritical]
    public WebClient() : base() { }
    protected override System.Net.WebRequest GetWebRequest(System.Uri address)
    {
      var wr = base.GetWebRequest(address);
      if (wr is System.Net.HttpWebRequest)
      {
        HttpWebRequest hwr = wr as HttpWebRequest;
        hwr.AllowAutoRedirect = AllowAutoRedirect;
        hwr.CookieContainer = CookieContainer;
      }
      return wr;
    }
  }
}
